package com.video.information.ui.common.holder

import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.dueeeke.videocontroller.component.PrepareView
import com.video.information.Const
import com.video.information.R
import com.video.information.extension.inflate

/**
 * 项目通用ViewHolder，集中统一管理。
 */

/**
 * 未知类型，占位进行容错处理。
 */
class EmptyViewHolder(view: View) : RecyclerView.ViewHolder(view)

class ItemVideoHolder(view: View) : RecyclerView.ViewHolder(view) {
    val tvTitle: TextView = view.findViewById(R.id.title)
    val tvAuthor: TextView = view.findViewById(R.id.author)
    val tvDz: TextView = view.findViewById(R.id.dz)
    val tvComment: TextView = view.findViewById(R.id.comment)
    val tvCollect: TextView = view.findViewById(R.id.collect)

    val imgHeader: ImageView = view.findViewById(R.id.img_header)
    val imgCollect: ImageView = view.findViewById(R.id.img_collect)
    val imgDan: ImageView = view.findViewById(R.id.img_like)
    val mThumb: ImageView = view.findViewById(R.id.thumb)

    val mPrepareView: PrepareView = view.findViewById(R.id.prepare_view)
    val mPlayerContainer: FrameLayout = view.findViewById(R.id.player_container)

    init {
        // 通过tag将ViewHolder和itemView绑定，用于操作videoView
        view.tag = this
    }
}

class ItemInformationHolderOen(view: View) : RecyclerView.ViewHolder(view) {
    val title: TextView = view.findViewById(R.id.title)
    val author: TextView = view.findViewById(R.id.author)
    val comment: TextView = view.findViewById(R.id.comment)
    val time: TextView = view.findViewById(R.id.time)
    val header: ImageView = view.findViewById(R.id.header)
    val thumb: ImageView = view.findViewById(R.id.thumb)
}

class ItemInformationHolderTwo(view: View) : RecyclerView.ViewHolder(view) {
    val title: TextView = view.findViewById(R.id.title)
    val author: TextView = view.findViewById(R.id.author)
    val comment: TextView = view.findViewById(R.id.comment)
    val time: TextView = view.findViewById(R.id.time)
    val header: ImageView = view.findViewById(R.id.header)
    val pic1: ImageView = view.findViewById(R.id.pic1)
    val pic2: ImageView = view.findViewById(R.id.pic2)
    val pic3: ImageView = view.findViewById(R.id.pic3)
}

class ItemInformationHolderThree(view: View) : RecyclerView.ViewHolder(view) {
    val title: TextView = view.findViewById(R.id.title)
    val author: TextView = view.findViewById(R.id.author)
    val comment: TextView = view.findViewById(R.id.comment)
    val time: TextView = view.findViewById(R.id.time)
    val header: ImageView = view.findViewById(R.id.header)
    val thumb: ImageView = view.findViewById(R.id.thumb)
}

object RecyclerViewHelp {
    fun getViewHolder(parent: ViewGroup, viewType: Int) =
        when (viewType) {

            Const.ITEM_VIDEO_HOLDER -> ItemVideoHolder(R.layout.video_item_layout.inflate(parent))

            Const.ITEM_INFORMATION_HOLDER1 -> ItemInformationHolderOen(
                R.layout.information_item_one.inflate(
                    parent
                )
            )

            Const.ITEM_INFORMATION_HOLDER2 -> ItemInformationHolderTwo(
                R.layout.information_item_two.inflate(
                    parent
                )
            )

            Const.ITEM_INFORMATION_HOLDER3 -> ItemInformationHolderThree(
                R.layout.information_item_three.inflate(
                    parent
                )
            )

            else -> EmptyViewHolder(parent)

        }
}
